<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    // flat 把多维数组转为低维数组
    let arr = [1, 2, [3, 4, [5, 6]]]
    console.log(arr.flat());   // [1, 2, 3, 4, [5, 6]]);        默认只降一层，三维数组变成二维数组了
    // 把 3 维数组转为 1 维，
    console.log(arr.flat(2));   // [1, 2, 3, 4, 5, 6]

    // flatMap
    const arr2 = [1, 2, 3, 4];
    const result = arr2.map(item => [item * 10]);   // 返回的是二维数组
    const result2 = arr2.flatMap(item => [item * 10]);    // 返回的是一维数组
    console.log(result);    // [[10], [20], [30], [40]]
    console.log(result2);   // [10, 20, 30, 40]

  </script>
</body>

</html>